package controller;

import view.*;

public class Controlador extends Thread {

	public Ventana ventana;
	
	public Controlador(Ventana ventana) {
		this.ventana = ventana;
	}
	
	public void run() {
		super.run();
				
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
		
		while(true) {
		
			if(!ventana.pelota.gol) {
				ventana.pelota.mover();
				ventana.repaint();
				
				try {
					Thread.sleep(30);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			} else {
				ventana.mostrarMarcador();
				ventana.repaint();

				try {
					Thread.sleep(1500);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
				ventana.ocultarMarcador();
				ventana.repaint();

				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				
				ventana.pelota.gol = false;
			}
			
		}
		
	}
}
